home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000154 / patchSG0000154.idb / usr / share / src / OpenGL / examples / double.c.z / double.c
Encoding:
C/C++ Source or Header  |  1995-06-12  |  1.8 KB  |  84 lines

  1. /*
  2.  *  double.c
  3.  *  This program demonstrates double buffering for 
  4.  *  flicker-free animation.  The left and middle mouse
  5.  *  buttons start and stop the spinning motion of the square.
  6.  */
  7. #include <GL/gl.h>
  8. #include <GL/glu.h>
  9. #include <GL/glx.h>
  10. #include "aux.h"
  11.  
  12. static GLfloat spin = 0.0;
  13.  
  14. void display(void)
  15. {
  16.     glClear (GL_COLOR_BUFFER_BIT);
  17.  
  18.     glPushMatrix ();
  19.     glRotatef (spin, 0.0, 0.0, 1.0);
  20.     glRectf (-25.0, -25.0, 25.0, 25.0);
  21.     glPopMatrix ();
  22.  
  23.     glXSwapBuffers (auxXDisplay(), auxXWindow());
  24. /*    glFlush(); */
  25. }
  26.  
  27. void spinDisplay (void)
  28. {
  29.     spin = spin + 2.0;
  30.     if (spin > 360.0)
  31.     spin = spin - 360.0;
  32.     display();
  33. /*    glFinish();  */
  34. }
  35.  
  36. void startIdleFunc (AUX_EVENTREC *event)
  37. {
  38.     auxIdleFunc(spinDisplay);
  39. }
  40.  
  41. void stopIdleFunc (AUX_EVENTREC *event)
  42. {
  43.     auxIdleFunc(0);
  44. }
  45.  
  46. void myinit (void)
  47. {
  48.     glClearColor (0.0, 0.0, 0.0, 1.0);
  49.     glColor3f (1.0, 1.0, 1.0);
  50.     glShadeModel (GL_FLAT);
  51. }
  52.  
  53. void myReshape(int w, int h)
  54. {
  55.     glViewport(0, 0, w, h);
  56.     glMatrixMode(GL_PROJECTION);
  57.     glLoadIdentity();
  58.     if (w <= h) 
  59.     glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w, 
  60.         50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
  61.     else 
  62.     glOrtho (-50.0*(GLfloat)w/(GLfloat)h, 
  63.         50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
  64.     glMatrixMode(GL_MODELVIEW);
  65.     glLoadIdentity ();
  66. }
  67.  
  68. /*  Main Loop
  69.  *  Open window with initial window size, title bar, 
  70.  *  RGBA display mode, and handle input events.
  71.  */
  72. int main(int argc, char** argv)
  73. {
  74.     auxInitDisplayMode (AUX_DOUBLE | AUX_RGB);
  75.     auxInitPosition (0, 0, 500, 500);
  76.     auxInitWindow (argv[0]);
  77.     myinit ();
  78.     auxReshapeFunc (myReshape);
  79.     auxIdleFunc (spinDisplay);
  80.     auxMouseFunc (AUX_LEFTBUTTON, AUX_MOUSEDOWN, startIdleFunc);
  81.     auxMouseFunc (AUX_MIDDLEBUTTON, AUX_MOUSEDOWN, stopIdleFunc);
  82.     auxMainLoop(display);
  83. }
  84.